package com.authsphere.security.token.common;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/12 10:34
 **/
public interface AuthenticationTokenServices {

    /**
     * Create an access token associated with the specified credentials.
     * @param authentication The credentials associated with the access token.
     * @param force the force create new token
     * @return The access token.
     * @throws AuthenticationException If the credentials are inadequate.
     */
    AccessToken createAccessToken(Authentication authentication, boolean force) throws AuthenticationException;

    /**
     * 刷新token
     * @param accessToken   an access token
     * @param authentication The credentials associated with the access token.
     * @throws AuthenticationException
     */
    AccessToken refreshAccessToken(AccessToken accessToken, Authentication authentication) throws AuthenticationException;

    /**
     * Retrieve an access token stored against the provided authentication key, if it exists.
     *
     * @param authentication the authentication key for the access token
     *
     * @return the access token or null if there was none
     */
    AccessToken getAccessToken(Authentication authentication);

    /**
     * Retrieve an access token stored against the provided token key, if it exists.
     * @param tokenValue tokenValue
     * @return the access token or null if there was none
     */
    AccessToken getAccessToken(String tokenValue);

    /**
     * Retrieve an Authentication stored against the provided tokenValue, if it exists.
     * @param tokenValue the token value
     * @return the Authentication
     */
    Authentication getAuthentication(String tokenValue);

    /**
     * remove access token
     * @param tokenValue tokenValue
     */
    void removeAccessToken(String tokenValue);
}
